package com.pan.behavioral.command.order.impl;

import com.pan.behavioral.command.order.MyScreenCommand;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;

public class PrintAndSignatureScreen extends MyScreenCommand {

    private Robot robot;
    {
        try {
            robot = new Robot();
        } catch (AWTException e) {
            throw new RuntimeException(e);
        }
    }
    private String sign;
    {
        sign = "潘祺安";
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    @Override
    public void execute() {
        BufferedImage screenCapture = robot.createScreenCapture(new Rectangle(super.x, super.y, super.width, super.height));
        Graphics2D graphics = screenCapture.createGraphics();
        graphics.setColor(Color.RED);
        graphics.setFont(new Font("宋体",Font.BOLD,18));
        graphics.drawString(sign,0,30);
        JFrame frame = new JFrame("screen capture");
        frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        JLabel pictureLabel = new JLabel(new ImageIcon(screenCapture));
        frame.add(pictureLabel);
        frame.pack();
        frame.setVisible(true);
    }
}
